<template>
  <div class="app-container">

    <el-input v-model="filterText" placeholder="Filter keyword" style="margin-bottom:30px;"/>
    <el-tree
      ref="tree"
      :data="categoryData"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />

  </div>
</template>

<script>
import category from "@/api/yydm/category";

export default {
  name: "list",

  //初始化值
  data() {
    return {
      filterText: '',
      categoryData: [],  //返回所有分类数据
      defaultProps: {
        children: 'children',
        label: 'name'
      }
    }
  },

  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    }
  },

  //页面渲染前执行,调用methods里面的方法
  created() {
    this.getCategoryList();
  },

  methods: {
    getCategoryList() {
      category.getCategoryList()
        .then(response => {
          this.categoryData = response.data.list
        })
    },
    filterNode(value, data) {
      if (!value) return true
      return data.name.indexOf(value) !== -1
    }

  }

}
</script>

<style scoped>

</style>
